/*
 * $Id: ApplicationServiceImpl.java 43 2007-05-14 10:18:31Z aaron.day $
 */
package org.crazydays.core;


import org.hibernate.Session;
import org.hibernate.HibernateException;

import org.crazydays.core.data.PolisApplication;
import org.crazydays.hibernate.HibernateUtil;

/**
 * ApplicationServiceImpl
 */
public class ApplicationServiceImpl
	extends AbstractService
	implements IApplicationService
{
	/**
	 * Load application by name.
	 * 
	 * @param session Session
	 * @param name Name
	 * @throws DataException
	 */
	public PolisApplication loadApplication(Session session, String name)
		throws DataException
	{
		if (session == null) {
			throw new IllegalArgumentException("session == null");
		}
		if (name == null) {
			throw new IllegalArgumentException("name == null");
		}

		try {
			PolisApplication application = (PolisApplication) HibernateUtil
					.loadPolisDataByName(
							PolisApplication.class,
							name);

			LOG.debug("Loaded: " + application);

			return application;
		} catch (HibernateException e) {
			LOG.error("HibernateException: " + e.getMessage(), e);
			throw new DataException("Unable to load Application: "
					+ name, e);
		}
	}
}
